package com.tanjun.data.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * 配置线程池
 */

@Configuration
public class ThreadPoolConfig {

    @Bean
    @Primary
    public Executor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5); //核心线程池数量
        executor.setMaxPoolSize(20); //最大线程池数量
        executor.setQueueCapacity(1000); //队列容量
        executor.setKeepAliveSeconds(60); //线程吃空闲时间
        executor.setThreadNamePrefix("TaskExecutor-"); //线程池前缀
        executor.initialize(); //初始化
        return executor;
    }
}
